/**

This file is part of MaCI/GIMnet.

MaCI/GIMnet is free software: you can redistribute it and/or modify it 
under the terms of the GNU Lesser General Public License as published 
by the Free Software Foundation, either version 3 of the License, or 
(at your option) any later version.

MaCI/GIMnet is distributed in the hope that it will be useful, but WITHOUT 
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public 
License for more details.

You should have received a copy of the GNU Lesser General Public 
License along with GIMnet. (See COPYING.LESSER) If not, see 
<http://www.gnu.org/licenses/>.

**/
# -*- coding: utf-8 -*-
import sys, time
sys.path.append("../../../interfaces/wrap/Python/lib")
sys.path.append("../../../../GIMI/wrap/Python/lib")
import TaskCtrlServer
import gimi
#if sys.argv.__len__() != 2:
#	print "Usage: python %s serverName"%sys.argv[0]
#	sys.exit()
g = gimi.GIMI()


#print "set target"
#tcc.SetDefaultTarget(sys.argv[2])
#tcc.SetDefaultTarget("testPyCoordServer")

g = gimi.GIMI()
mcs = TaskCtrlServer.CMaCICtrlServer(g)
tcs = TaskCtrlServer.CTaskCtrlServer(mcs, 0, "dummy TaskCtrl server")
name = "testPyCoordServer"
mcs.SetGroupName("hinkuvinku")
# set Instance name 
tcs.SetInterfaceInstanceName("suurvisiiri")

print "connecting... ",
#ret = g.connectToHubEx("asrobo.hut.fi", 40002, sys.argv[1])
ret = g.connectToHubEx("asrobo.hut.fi", 40002, "testTaskServ")
print TaskCtrlServer.GetErrorStr(ret)

r = tcs.Open()
data = CDS.CCoordinateDriveData()
info = CDS.TReplyInfo(0,0) 
print sys.argv[1], 
print(" is listening:" )
#enter the loop
try:
	while True:
		r = cds.WaitCommand(data, info,1000)
		if r:
			continue
		else:
			print "got command ", data.GetCommand().cmd
			if data.GetCommand().cmd == CDS.KCommandSetStop:
				print "got stop"
				break
			
except KeyboardInterrupt:
	print "moi moi"

cds.Close()
